package com.caigou.modules.tools.repository

import com.caigou.comm.base.bean.HttpResult
import com.caigou.modules.tools.bean.ActiveBean
import com.caigou.modules.tools.bean.CardBean
import com.caigou.modules.tools.bean.RedPackageBean
import com.caigou.modules.tools.bean.UserSignInBean
import com.caigou.modules.tools.network.HttpToolsService
import dagger.hilt.android.scopes.ActivityRetainedScoped
import kotlinx.coroutines.flow.Flow
import okhttp3.RequestBody.Companion.toRequestBody
import org.json.JSONObject
import javax.inject.Inject

/**
 * @author #Suyghur.
 * Created on 2021/10/26
 */
@ActivityRetainedScoped
class ToolsRepository @Inject constructor() {

    fun getCardList(userId: String): Flow<HttpResult<CardBean>> {
        return HttpToolsService.service.getCardList(userId)
    }

    fun getActiveInfo(userId: String): Flow<HttpResult<ActiveBean>> {
        return HttpToolsService.service.getActiveInfo(userId)
    }

    fun setUserSignIn(userId: String): Flow<HttpResult<UserSignInBean>> {
        return HttpToolsService.service.setUserSignIn(userId)
    }

    fun getRedPackage(userId: String, taskId: Int): Flow<HttpResult<RedPackageBean>> {
        return HttpToolsService.service.getRedPackage(userId, taskId)
    }

    fun exchangeRenameCard(userId: String): Flow<HttpResult<String>> {
        val jsonObject = JSONObject()
        jsonObject.put("userId", userId)
        val body = jsonObject.toString().toRequestBody()
        return HttpToolsService.service.exchangeRenameCard(body)
    }

    fun exchangeDeleteCard(userId: String): Flow<HttpResult<String>> {
        val jsonObject = JSONObject()
        jsonObject.put("userId", userId)
        val body = jsonObject.toString().toRequestBody()
        return HttpToolsService.service.exchangeDeleteCard(body)
    }


    fun buyFlower(userId: String, number: Int): Flow<HttpResult<String>> {
        val jsonObject = JSONObject()
        jsonObject.put("userId", userId)
        jsonObject.put("number", number)
        val body = jsonObject.toString().toRequestBody()
        return HttpToolsService.service.buyFlower(body)
    }
}